﻿cmake_minimum_required (VERSION 3.8)

project ("WineBDLauncher")

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

include (ExternalProject)
include (Utility)

generate_git_version (git_version)

option (NO_INLINE off)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS ON)
set (VCPKG_TARGET_TRIPLET "x64-windows-rel")

if (NO_INLINE)
    add_compile_options (/Ob0)
endif ()

include_directories (Public)
add_compile_definitions (_UNICODE UNICODE NDEBUG)
add_compile_options (-Wno-invalid-offsetof -Wno-deprecated-declarations)

file (GLOB_RECURSE MinecraftHeadersFiles CONFIGURE_DEPENDS MinecraftHeaders/*)
add_custom_target (MinecraftHeaders SOURCES ${MinecraftHeadersFiles})
install (DIRECTORY MinecraftHeaders DESTINATION Include)

file (GLOB_RECURSE PublicHeadersFiles CONFIGURE_DEPENDS Public/*)
add_custom_target (PublicHeaders SOURCES ${PublicHeadersFiles})
install (DIRECTORY Public DESTINATION Include)

add_library (BedrockServer INTERFACE)
target_include_directories (BedrockServer INTERFACE MinecraftHeaders)
target_link_directories (BedrockServer INTERFACE Lib)
target_link_libraries (BedrockServer INTERFACE bedrock_server_mod)

find_package (SQLiteCpp CONFIG REQUIRED)
find_package (Boost 1.72.0 REQUIRED)
find_and_install_package (sqlite3 CONFIG REQUIRED)
find_and_install_package (yaml-cpp CONFIG REQUIRED)
find_package (msgpack CONFIG REQUIRED)
find_package (gsl-lite CONFIG REQUIRED)

function (install_pdb name)
    install (FILES $<TARGET_PDB_FILE:${name}> DESTINATION Lib)
endfunction ()
function (add_mod name)
    file (GLOB_RECURSE srcs CONFIGURE_DEPENDS *.cpp)
    add_library (${name} SHARED ${srcs})
    target_compile_definitions (${name} PRIVATE MODNAME=${name})
    target_link_libraries (${name} Boost::headers yaml-cpp ModLoader BedrockServer Base)
    install (TARGETS ${name} RUNTIME DESTINATION Mods ARCHIVE DESTINATION Lib)
    install_pdb (${name})
    set_target_properties (${name} PROPERTIES FOLDER Mods)
endfunction ()
function (add_base_mod name)
    file (GLOB_RECURSE srcs CONFIGURE_DEPENDS *.cpp *.hint)
    add_library (${name} SHARED ${srcs})
    target_compile_definitions (${name} PRIVATE MODNAME=${name} EZVERSION=\"${git_version}\")
    target_link_libraries (${name} Boost::headers yaml-cpp ModLoader BedrockServer)
    install (TARGETS ${name} RUNTIME DESTINATION . ARCHIVE DESTINATION Lib)
    install_pdb (${name})
    set_target_properties (${name} PROPERTIES FOLDER Base)
endfunction ()
function (mod_link name)
    target_link_libraries (${name} ${ARGN})
endfunction ()

add_subdirectory ("ModLoader")
add_subdirectory ("Base")
add_subdirectory ("BuiltinMods")
